﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mall.Application
{
    public class ProductService : IProductService, ITransient
    {
        private readonly IRepository<Product> _productRepository;
        public ProductService(IRepository<Product> productRepository)
        {
            _productRepository = productRepository;
        }
        public PagedList<ProductDtoOutput> GetPagedList(ProductDtoInput input)
        {
            var query = _productRepository.DetachedEntities.Include(x => x.Category).Where(x => true);

            //if (!string.IsNullOrEmpty(input.Name))
            //{
            //    query = query.Where(x => x.StudentName.Contains(input.Name));
            //}

            var list = query
                .OrderByDescending(x => x.Id)
                .ProjectToType<ProductDtoOutput>().ToPagedList(input.Page, input.Limit);

            return list;

        }
    }
}
